package erreAga.dao.toplink;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import erreAga.dao.AtestadoMedicoDao;
import erreAga.eb.AtestadoMedico;


public class AtestadoMedicoDaoToplinkImpl implements AtestadoMedicoDao {

  @Override
  public void deleteAtestadoMedico(AtestadoMedico atestadoMedico) {
    EntityManager manager = DatabaseManagerSingletonToplinkImpl.getInstancia().getManager();
    manager.getTransaction().begin();
    manager.remove(atestadoMedico);
    manager.getTransaction().commit();
  }

  @Override
  public AtestadoMedico getAtestadoMedico(Integer id) {
    EntityManager manager = DatabaseManagerSingletonToplinkImpl.getInstancia().getManager();
    return manager.find(AtestadoMedico.class, id);
  }

  @Override
  public AtestadoMedico saveAtestadoMedico(AtestadoMedico atestadoMedico) {
    EntityManager manager = DatabaseManagerSingletonToplinkImpl.getInstancia().getManager();
    manager.getTransaction().begin();
    manager.persist(atestadoMedico);
    manager.getTransaction().commit();
    return atestadoMedico;
  }

  @SuppressWarnings("unchecked")
  @Override
  public List<AtestadoMedico> searchAtestadoMedico() {
    EntityManager manager = DatabaseManagerSingletonToplinkImpl.getInstancia().getManager();
    Query query=manager.createQuery ("select a from AtestadoMedico a");
    List<AtestadoMedico> resultList = (List<AtestadoMedico>) query.getResultList();
    return resultList;
  }


}
